library(devtools)
source_url("https://gitee.com/ry2an/my_public_functions_r/raw/master/strict_isna.R")
replace_vector_na <- function(x = c(), replacement = "not_ava", strict = T){
  out <- x
  if(strict){
    for(i in 1:length(x)){
      if(strict_isna(x[i])){
        out[i] <- replacement
      }
    }
  }else{
    for(i in 1:length(x)){
      if(is.na(x[i])){
        out[i] <- replacement
      }
    }
  }
  return(out)
}



replace_dataframe_na <- function(x = data.frame(), replacement = "not_ava", strict = T){
  num_vecs <- dim(x)[2]
  for(i in 1:dim(x)[2]){
    x[,c(i)] <- replace_vector_na(x = x[,c(i)], replacement = replacement, strict = strict)
  }
  return(x)
}
i = 4
#### test area ####
# replace_vector_na(c(1,2,3,NA,5))
# replace_vector_na(x = c(1,NA,5), replacement = "not_ava", strict = T)
# 
# test_df <- data.frame("v1" = c(1,2,3,NA,5), "v2" = c(1,2,3,NA,5), "v3" = c(1,2,3,NA,5))
# replace_dataframe_na(x = test_df, strict = T)
# 
# test_df <- data.frame("v1" = c("1",NA,"3","",NA), "v2" = c(1,2,3,NA,5), "v3" = c(1,2,3,NA,5))
# replace_dataframe_na(x = test_df, strict = T)
# 
# test_df <- data.frame("v1" = c("1",NA,"3","",NA), "v2" = c(1,2,3,NA,5), "v3" = c(1,2,3,NA,5))
# replace_dataframe_na(x = test_df, strict = F)
